<template>
  <el-dialog :visible.sync="visible"  width="800px" top="75px" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" @open="open" @close="close" :append-to-body="true" :modal-append-to-body="true">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="100px" :disabled="disableEditSubmit">
      <el-tabs v-model="activeTab" type="card">
        <el-tab-pane label="基础信息" name="basic">
          <el-row v-if="isFromMenu">
            <el-col :span="12">
              <el-form-item label="所属会议" prop="meetId" :rules="rules.validateRequire">
                <el-input v-model="model.meetName" :disabled="true" class="tl-ref-selector">
                  <el-button slot="append" type="primary" icon="el-icon-search" @click="openMeetManageRefDialog"></el-button>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="发起日期" prop="initiatedate">
                <el-date-picker v-model="model.initiatedate" value-format="yyyy-MM-dd"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="任务编号" prop="tasknumber">
                <el-input v-model="model.tasknumber" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="任务分类" prop="category" :rules="rules.validateRequire">
                <el-select v-model="model.category" filterable clearable>
                  <el-option v-for="item in codeModelFromOA.taskCategoryList" :key="'category' + item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否延期" prop="isdelay">
                <el-input v-model="model.dispisdelay" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="责任人" prop="handleusercode">
                <tl-ref-user v-model="model.handleusercode" :initDisplayData.sync="model.handleusername" dataType="code" :singleSelect="true" :externalQueryParam="{qry_whereSql:'EXTENDFIELD1 IS NOT NULL AND ENABLED = 1',qry_nodimission:'0'}" ></tl-ref-user>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="归属部门" prop="relegationdeptname">
                <el-input v-model="model.relegationdeptname" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 发起人和记录人隐藏
          <el-row>
            <el-col :span="12">
              <el-form-item label="发起人" prop="initiatorcode" :rules="rules.validateRequire">
                <tl-ref-user v-model="model.initiatorcode" :initDisplayData.sync="model.initiatorname" dataType="code" :singleSelect="true" @confirm="confirmInitiator" :externalQueryParam="{qry_whereSql:'EXTENDFIELD1 IS NOT NULL AND ENABLED = 1',qry_nodimission:'0'}" ></tl-ref-user>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="记录人" prop="usercode" :rules="rules.validateRequire">
                <el-input v-model="model.username" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row> -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="时间要求" prop="daterequirement" :rules="rules.validateRequire">
                <el-select v-model="model.daterequirement" filterable clearable>
                  <el-option v-for="item in codeModelFromOA.dateRequirementList" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="model.daterequirement === '1'">
              <el-form-item label="截止日期" prop="enddate" :rules="model.daterequirement === '1' ? rules.validateRequire : { required: 'false' }">
                <el-date-picker v-model="model.enddate" value-format="yyyy-MM-dd"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="任务主题" prop="taskmaintitle" :rules="rules.validateRequire">
                <el-input v-model="model.taskmaintitle"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="总延期天数" prop="delaydays">
                <el-input v-model="model.delaydays" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="任务内容" prop="taskdescription" :rules="rules.validateRequire">
                <el-input v-model="model.taskdescription" type="textarea" :rows="2"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="转办记录" prop="recordhis">
                <el-input v-model="model.recordhis" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="任务进度" name="schedule">
          <el-row>
            <el-col :span="24">
              <el-form-item label="办理进度" prop="taskschedule">
                <el-input v-model="model.taskschedule" type="textarea" :rows="10" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 评价信息隐藏
          <el-row>
            <el-col :span="12">
              <el-form-item label="评价等级" prop="evaluationlev">
                <el-input v-model="model.dispevaluationlev" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="评价内容" prop="evaluationcon">
                <el-input v-model="model.taskschedule" type="textarea" :rows="2" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="责任人总结" prop="summaryhan">
                <el-input v-model="model.summaryhan" type="textarea" :rows="2" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="发起人总结" prop="summaryini">
                <el-input v-model="model.summaryini" type="textarea" :rows="2" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row> -->
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
    <tl-ref-meet-manage ref="meetManageRef" :singleSelect="true" @confirm="getMeetManageRefData" :externalSelectedRowKeys="'model.meetId'"></tl-ref-meet-manage>
    <tl-ref-team ref="teamRef" :singleSelect="true" @confirm="getTeamRefData" :externalSelectedRowKeys="'model.handleteamids'"></tl-ref-team>
  </el-dialog>
</template>
<script>
/** mixins */
import { mixin_edit } from "@tapui/mixins/mixin_edit"
/** 子组件 */
import tlRefMeetManage from "../meetManage/refList"
import tlRefTeam from "../../base/baseTeamInfo/refList"
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from "@tapui/utils/http"
import axios from "axios"
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: { tlRefMeetManage, tlRefTeam },
  data() {
    return {
      moduleTitle: "已下发任务项",
      urlPrefix: "/meet/taskManage/",
      activeTab: "basic",
      url: {
        // 额外的url
        queryCodeList: "",
        queryUsers: "/meet/taskManage/queryUsersByCondition"
      }
    }
  },
  props: {
    // 是否是从菜单页面进入的
    isFromMenu: {
      type: Boolean,
      default: true
    },
    codeModelFromOA: {
      type: Object,
      default: function() {
        return {}
      }
    },
    sourceMeetID: {
      type: [Number, String],
      default: ""
    }
  },
  methods: {
    loaded() {
      // 页面加载完毕执行
      if (!this.isFromMenu && this.isAdd) {
        this.model.meetId = this.sourceMeetID
      }
    },
    /** 弃用，部门后台查询得到 */
    confirmHandleUser(selectedData) {
      const { deptid, dispdeptid } = selectedData[0]
      // 根据用户查询部门，并给部门信息赋值
      this.$set(this.model, "relegationdeptid", deptid)
      this.$set(this.model, "relegationdeptname", dispdeptid)
    },
    confirmInitiator(selectedData) {
      const { code, name } = selectedData[0]
      this.$set(this.model, "usercode", code)
      this.$set(this.model, "username", name)
    },
    /** 重写open方法，页面打开时执行*/
    open() {
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
        if (this.isAdd === true) {
          this.title = "添加" + this.moduleTitle
          // 需要添加重复判断
          if (this.$store.getters.param.isAvoidRepeat === true) {
            this.queryBillUid()
          }
          if (this.isQueryInitData === true) {
            // 后台进行数据初始化
            this.queryInitData().then((_) => {
              this.assignDefaultValue()
              this.loaded()
              this.model = {}
            })
          } else {
            // 前台进行数据初始化
            this.model = {}
            this.assignDefaultValue()
            this.loaded()
          }
        } else if (this.disableEditSubmit === false) {
          this.title = "编辑" + this.moduleTitle
        } else {
          this.title = "查看" + this.moduleTitle
        }
      })
    },
    /** 打开会议管理参照 */
    openMeetManageRefDialog() {
      this.$refs.meetManageRef.visible = true
    },
    /** 获取会议管理参数数据 */
    getMeetManageRefData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, "meetId", selectionRow.id)
      this.$set(this.model, "meetName", selectionRow.name)
    },
    /** 打开团队参照 */
    openTeamRefDialog() {
      this.$refs.teamRef.visible = true
    },
    /** 获取团队数据 */
    getTeamRefData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, "handleteamids", selectionRow.id)
      this.$set(this.model, "handleteamnames", selectionRow.name)
    }
  }
}
</script>
